//
//  LoreTableViewCell.m
//  项目三
//
//  Created by rimi1 on 2016/12/14.
//  Copyright © 2016年 Wangxingqian. All rights reserved.
//

#import "LoreTableViewCell.h"

static NSInteger spacing_ = 20;

@implementation LoreTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self.contentView addSubview:self.img];
        [self.contentView addSubview:self.title];
        [self.contentView addSubview:self.descriptionLore];
    }
    return self;
}

- (void)layoutSubviews {
    [super layoutSubviews];
    CGRect rect = self.descriptionLore.frame;
    rect.size.width = CGRectGetWidth(self.title.bounds);
    self.descriptionLore.frame = rect;
    [self.descriptionLore sizeToFit];
}

#pragma mark - set

- (void)setModel:(LoreModel *)model {
    _model = model;
    
    NSURL *url = [NSURL URLWithString:model.img];
    [self.img sd_setImageWithURL:url placeholderImage:nil options:SDWebImageProgressiveDownload];
    self.title.text = model.title;
    self.descriptionLore.text = model.descriptionLore;
}

#pragma mark - get

- (UIImageView *)img {
    
    if (!_img) {
        
        CGFloat height = WXQAdaptionHeight(80);
        CGFloat width = height/4 * 5;
        _img = [[UIImageView alloc] initWithFrame:CGRectMake(spacing_/2, spacing_/2, width, height)];
        _img.layer.cornerRadius = WXQAdaptionWidth(5);
        _img.layer.masksToBounds = YES;
        
    }
    return _img;
}

- (UILabel *)title {
    
    if (!_title) {
        
        CGFloat height = WXQAdaptionHeight(16);
        CGFloat x = CGRectGetMaxX(self.img.frame) + spacing_/2;
        _title = [[UILabel alloc] initWithFrame:CGRectMake(x, CGRectGetMinY(self.img.frame) + 5, kWIDTH - x - spacing_/2, height)];
        _title.font = [UIFont systemFontOfSize:height];
        
    }
    return _title;
}

- (UILabel *)descriptionLore {
    
    if (!_descriptionLore) {
        
        CGFloat height = WXQAdaptionHeight(26);
        _descriptionLore = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMinX(self.title.frame), CGRectGetMaxY(self.title.frame) + spacing_/2, CGRectGetWidth(self.title.bounds), height)];
        _descriptionLore.font = [UIFont systemFontOfSize:height/2];
        _descriptionLore.numberOfLines = 2;
        _descriptionLore.textColor = [UIColor lightGrayColor];
        
    }
    return _descriptionLore;
}


@end













